import { createWebHistory, createRouter } from 'vue-router'
import type { RouteRecordRaw } from "vue-router"
/* Layout */
import Layout from '@/layout'
import Login from '@/views/Login/IndexView.vue'
import NotFound from '@/views/status/404.vue'

// 公共路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    component: Layout,
    name: "layout",
    redirect: {
      name: "home"
    },
    children: [
      {
        path: "/home",
        name: "home",
        component: () => import("@/views/HomeView.vue")
      }
    ]
  },
  {
    path: "/login",
    name: "login",
    component: Login
  },
  {
    path: '/:catchAll(.*)',
    name: "404",
    component: NotFound
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
});

export default router;

